<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class kelas_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert($data){
		$this->db->insert('kelas',$data);
	}
	
	//list flexy
	function get_data_kelas($id_periode){
		//Select table name
		$table_name = "kelas";
		
		//Build contents query
		$this->db->select('*')->from($table_name);
		$this->db->join('ustad','kelas.ID_ustad = ustad.ID_ustad', 'left');
		$this->db->where('kelas.ID_PERIODE', $id_periode);
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('*')->from($table_name);
		$this->db->join('ustad','kelas.ID_ustad = ustad.ID_ustad', 'left');
		$this->db->where('kelas.ID_PERIODE', $id_periode);
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();
	
		//Return all
		return $return;
	}	
	
	
	
	function delete($id){
		$this->db->where('ID_kelas', $id);
		$this->db->delete('kelas');
	}
	
	function selectone($id){
		$this->db->select("*");
		$this->db->from('kelas');
		$this->db->where('ID_kelas',$id);
		$query = $this->db->get();
		return $query;
	}
	
	function update($id, $data){
		$this->db->where('ID_kelas',$id);
		$this->db->update('kelas',$data);
	}
	
	function get_kelas_by_period() {
		$this->db->select("*")->from('kelas AS K');;
		$this->db->join('PERIODE AS P','K.ID_PERIODE = P.ID_PERIODE','left');		
		$query = $this->db->get();
		return $query;
	}
	
}

?>